package kitrobot.com.bed.Service;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import kitrobot.com.bed.StreamTools;

public class TransferService {
    public static String TransferByClientPost(String phone,String codes,String status,String bed_id,String token){
    try{

        HttpClient client=new DefaultHttpClient();
        String path="http://47.106.217.3:8360/app/user/changeadmin";
        HttpPost httpPost=new HttpPost(path);

        List<NameValuePair> parmeters=new ArrayList<NameValuePair>();
        parmeters.add(new BasicNameValuePair("phone",phone));
        parmeters.add(new BasicNameValuePair("code",codes));
        parmeters.add(new BasicNameValuePair("status",status));
        parmeters.add(new BasicNameValuePair("bed_id",bed_id));
        httpPost.setEntity(new UrlEncodedFormEntity(parmeters,"UTF-8"));
        httpPost.addHeader("Authorization",token);
        HttpResponse response=client.execute(httpPost);
        int code=response.getStatusLine().getStatusCode();
        if(code==200) {
            InputStream is = response.getEntity().getContent();
            String text = StreamTools.readInputStream(is);
             return text;

        }
        else{
            return null;
        }
    }catch (Exception e){
        e.printStackTrace();
        return null;
    }
    }
}
